<?php if (!defined('THINK_PATH')) exit();?><section class="content-header" >
    <h1>
        任务管理
        <small>任务列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo U('/Admin/index');?>"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">任务管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >任务列表</label></div>
                    <div class="pull-right">
                        <button class="btn btn-block btn-primary btn-sm "onclick="addTaskToCar()"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;指派任务</button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>装料站</th>
                                <th>抵达地址</th>
                                <th>安排车辆</th>
                                <th>方量</th>
                                <th>下达时间</th>
                                <!--<th>计算费用</th>-->
                                <th>线路</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    var taskTable = null;
    $(function () {
        taskTable =  $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "<?php echo U('Task/index');?>",
                "type": "POST"
            },
            "columns": [
                {"data": "task_from"},
                {"data": "task_end"},
                {"data": "car_name"},
                {"data": "total_load"},
                {"data": "public_time"},
//                {"data": "cost"},
                {"data": "roads_id"},
                {"data": "status"},
                {"data": "id"}
            ],
            "columnDefs": [
                {
                    "targets": 0,
                    "render": function (data, type, row) {
                        return data+"<br/>装料口:"+row.load_site;
                    }
                },
                {
                    "targets": 1,
                    "render": function (data, type, row) {
                        return "联系人:"+row.linkman+",电话:"+row.mobile+"<br/>"+data;
                    }
                },
                {
                    "targets": 2,
                    "render": function (data, type, row) {
                        return data+"<br/>车牌:"+row.car_no+"|载重:"+row.car_load;
                    }
                },
                {
                    "targets": 3,
                    "render": function (data, type, row) {
                        var types =['泵送','<span style="color:#0278C1">塔吊</span>','直卸','斗卸'];
                        var bd = '';
                        if(row.cost_load!=data){
                            bd = '&nbsp;<span style="color:red">保底:'+row.cost_load+"</span>";
                        }
                        return data+bd+"<br/>"+types[row.unload_type]+"<br/>标号:"+row.grade+"&nbsp;施工部位:"+row.components;
                    }
                },
                {
                    "targets": 5,
                    "render": function (data, type, row) {
                            return "<a href='javascript:getRoads(" + data + "," + row.task_from_longitude + "," + row.task_from_latitude + ","
                                    + row.task_end_longitude + "," + row.task_end_latitude + ")'>查看线路</a>";
                        return '';
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row) {
                        if(data==0){
                            return "待开始";
                        }else if(data==1) {
                            return "<span style='color: blue;'>待执行</span>";
                        }else if(data==2){
                                return "<span style='color: green;'>执行中</span>";
                        }else if(data==3){
                            var note = "";
                            if(row.note!=null){
                                note = "<br/>说明:"+row.note;
                            }
                            return "<span style='color: red;'>放弃</span>"+note;
                        }else if(data==4){
                            var note = "";
                            if(row.note!=null){
                                note = "<br/>说明:"+row.note;
                            }
                            return "<span style='color: #1a68ff;'>已完成</span>"+note;
                        }
                    }
                },
                {
                    "targets": 7,
                    "render": function (data, type, row) {
                        var html ="";
                        if(row.status==0){
                           html =  '<a href="javascript:sendToCar(' +data + ')"><i class="fa fa-flag"></i>&nbsp;执行</a><br/>';
                            html+='<a href="javascript:uptateItem(' +data + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a><br/>';
                        }
                        if(row.status==0||row.status==1||row.status==2){
                            html+='<a href="javascript:lossItem(' +data + ')" style="color:red;"><i class="fa fa-ban"></i>&nbsp;放弃任务</a>';
                        }
                        if(row.status==2){
                            html+='<br/><a href="javascript:finishTask(' +data + ')" ><i class="fa fa-flag"></i>&nbsp;完成任务</a>';
                        }
                        html+='<br/><a href="javascript:copyItem(' +data + ')" ><i class="fa fa-copy"></i>&nbsp;复制</a>';
                        return html;
                    }
                }
            ],
            "language": lang
        });

    });

    function uptateItem(id) {
        var url = "<?php echo U('task/add');?>";
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $.dialog(url, '修改任务信息', null,50);
    }

    function copyItem(id) {
        var url = "<?php echo U('task/add');?>";
        url += '?id=' + id+"&copy=1";
        $.dialog(url, '添加任务信息', null,50);
    }



    //    function lossItem(id) {
//        $.messager.confirm('确定放弃任务','确定放弃任务吗?',function(){
//            $.post("<?php echo U('Task/losstask');?>","id="+id, function (res) {
//                if (!res.status) {
//                    $.messager.alert('提示信息', res.info, 'error');
//                } else {
//                    $.messager.alert('提示信息', res.info, 'info');
//                    taskTable.fnDraw(false);
//                }
//            });
//        });
//
//    }
    function lossItem(id){
        $.dialog("<?php echo U('task/loss');?>?id="+id, '确定放弃任务',null);
    }
    function finishTask(id){
        $.dialog("<?php echo U('task/finish');?>?id="+id, '确定完成任务',null);
    }


    function addTaskToCar() {
        $.dialog("<?php echo U('task/add');?>", '指派任务',null,50);
    }



    function getRoads(id,slong,slat,elong,elat){
        var url = '<?php echo U("Task/getRoads");?>?id='+id+'&type=2&slng='+slong+"&slat="+slat+'&elng='+elong+"&elat="+elat;
        $.dialog(url, '查看线路', null,46,'getRoads');
    }

    function sendToCar(id){
        var url = "<?php echo U('task/sendToCar');?>";
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $.dialog(url, '发布任务', null,40);
    }
</script>